using System;

namespace IQIGame.Onigao.Game
{
    public static class MathLogic
    {
        public static readonly float Deg2Rad = (float)(Math.PI / 180f);
        public static readonly float Rad2Deg = (float)(180.0 / Math.PI);
        //
        // 摘要:
        //     Linearly interpolates between a and b by t.
        //
        // 参数:
        //   a:
        //     The start value.
        //
        //   b:
        //     The end value.
        //
        //   t:
        //     The interpolation value between the two floats.
        //
        // 返回结果:
        //     The interpolated float result between the two float values.
        public static float Lerp(float a, float b, float t)
        {
            return a + (b - a) * Clamp01(t);
        }

        //
        // 摘要:
        //     Determines where a value lies between two points.
        //
        // 参数:
        //   a:
        //     The start of the range.
        //
        //   b:
        //     The end of the range.
        //
        //   value:
        //     The point within the range you want to calculate.
        //
        // 返回结果:
        //     A value between zero and one, representing where the "value" parameter falls
        //     within the range defined by a and b.
        public static float InverseLerp(float a, float b, float value)
        {
            if (a != b)
            {
                return Clamp01((value - a) / (b - a));
            }

            return (float)0f;
        }

        //
        // 摘要:
        //     Clamps value between 0 and 1 and returns value.
        //
        // 参数:
        //   value:
        public static float Clamp01(float value)
        {
            if (value < 0f)
            {
                return 0f;
            }

            if (value > 1f)
            {
                return 1f;
            }

            return value;
        }

        public static float Cos(float radAngle)
        {
            //暂时用Math实现，随时可以改
            return (float)Math.Cos(radAngle);
        }

        public static float Sin(float radAngle)
        {
            //暂时用Math实现，随时可以改
            return (float)Math.Sin(radAngle);
        }

        public static float Sqrt(float v)
        {
            //暂时用Math实现，随时可以改
            return (float)Math.Sqrt(v);
        }
    }
}
